package com.homework11;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

public class demo01 {
    public static void main(String[] args) throws IOException {
        HashMap<Character, Integer> characterIntegerHashMap = new HashMap<>();
        FileInputStream fileInputStream=new FileInputStream(new File("D:\\a.txt"));
        int len=0;
        while ((len=fileInputStream.read())!=-1){
            if(characterIntegerHashMap.containsKey((char)len)){
                int count=characterIntegerHashMap.get((char)len);
                characterIntegerHashMap.put((char)len,++count);
            }else {
                characterIntegerHashMap.put((char)len,1);
            }
        }
        fileInputStream.close();
        Set<Map.Entry<Character, Integer>> entries = characterIntegerHashMap.entrySet();
        Iterator<Map.Entry<Character, Integer>> iterator = entries.iterator();
        while (iterator.hasNext()){
            Map.Entry<Character, Integer> next = iterator.next();
            System.out.println("字母:"+next.getKey()+"出现次数为:"+next.getValue()+"次");
        }
    }
}
